package test2;

/**
 * @author spf
 * @date 2024/9/26
 * @time 20:28
 */

import java.util.Scanner;

/**
 * 恒生电子笔试
 */
//public class Main4 {
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        long c = sc.nextLong();
//
//        long maxProduct;
//
//        if(c%2==0){
//            long k = c/2;
//            maxProduct = k*k;
//        }else{
//            long k = c/2;
//            maxProduct = k*(k+1);
//        }
//
//        System.out.println(maxProduct);
//    }
//}

public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] a = new long[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        long result = maxGcdSum(a, k,n);
        System.out.println(result);
    }

    private static long maxGcdSum(long[] a, long k, int n) {

        long maxS = -1;
        long currentSum = 0;
        long[] gcdList = new long[n- 1];

        for (int i = 0; i < n - 1; i++) {
            gcdList[i] = gcd(a[i], a[i + 1]);
        }

        int l = 0;
        for (int r = 0; r < n; r++) {
            currentSum += a[r];
            while (currentSum > k && l <= r) {
                currentSum -= a[l];
                l++;
            }
            if (l<r){
                long currentGcd = 0;
                for (int i = l; i < r; i++) {
                    currentSum += gcdList[i];
                }

                maxS = Math.max(maxS, currentSum);
            }
        }
        return maxS;
    }

    private static long gcd(long l, long l1) {

        while (l1 != 0){
            long temp = l1;
            l1 = l % l1;
            l = temp;
        }

        return l;
    }
}
